/**
 * Author: Zane
 * Email: 873934580@qq.com
 * Date: 2023/5/2
 */
import { program } from 'commander'
import chalk from 'chalk'
import * as path from 'path'
import * as fs from 'fs'
import {execa} from "execa";

const ROOT_PATH = process.cwd()
const pkgUrl = path.join(ROOT_PATH, 'package.json')
const pack = JSON.parse(fs.readFileSync(pkgUrl, 'utf8'))

program.on('--help', () => {
    console.log('  ==================================')
    console.log(chalk.blue.bold('  Usage:'), chalk.cyan.bold('工具节点构建器'))
    console.log('  ==================================')
})

program.version(`${pack['name']} v${pack['version']}`, '-v, --version', `${pack['description']}`)

program
    .command('dev')
    .action(async (_, args) => {
        const { stdout } = await execa('vite', ['div'], {stdio: 'inherit' })

        console.log(stdout)
    })

program.parse(process.argv)

